<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

<mapper namespace="com.otod.${moduleName}.${packageName}.mapper.${beanNamePre}Mapper" >

	<!-- 新增 -->
	<insert id="insert" parameterType="com.otod.${moduleName}.${packageName}.vo.${beanName}">
		insert into ${tableName}
		(
		<#list column as c>
  			<#if c_index &gt; 0>,</#if>${c.columnName}
    	</#list>
    	)
    	values
    	(
		<#list column as c>
  			<#if c_index&gt;0>,</#if> ${"#"}{${c.fieldName}}
    	</#list>
    	)
	</insert>
	
	<!-- 修改 -->
	<update id="update" parameterType="java.util.Map">
		update ${tableName}
		<trim prefix="SET" suffixOverrides=",">
			<#list column as c>
				<#if !c.prikey>
	  				<if test="_parameter.containsKey('${c.fieldName}')">  
	  					${c.columnName} = ${"#"}{${c.fieldName}},  
	  				</if>		
	  			</#if>
	    	</#list>
    	</trim>
		where 
		<#list column as c>
			<#if c.prikey>
  			${c.columnName} = ${"#"}{${c.fieldName}}				
  			</#if>
    	</#list>
	</update>
	
	<!-- 删除 -->
	<delete id="deleteById" parameterType="java.lang.String">
		delete from ${tableName}
		where 
		<#list column as c>
			<#if c.prikey>
  			${c.columnName} = ${"#"}{id}				
  			</#if>
    	</#list>
	</delete>
	
	<!-- 主键查询 -->
	<select id="getById" resultType="com.otod.${moduleName}.${packageName}.vo.${beanName}" parameterType="java.lang.String">
		select	
		<#list column as c>
  			<#if c_index &gt; 0>,</#if>${c.columnName} ${c.fieldName}
    	</#list>
		from ${tableName}
		where 
		<#list column as c>
			<#if c.prikey>
  			${c.columnName} = ${"#"}{id}				
  			</#if>
    	</#list>
	</select>
	
	<!-- 列表查询 -->
	<select id="queryForList" resultType="com.otod.${moduleName}.${packageName}.vo.${beanName}" parameterType="java.util.Map">
		select	
		<#list column as c>
  			<#if c_index &gt; 0>,</#if>${c.columnName} ${c.fieldName}
    	</#list>
		from ${tableName}
		<trim prefix="WHERE" prefixOverrides="AND |OR "> 
			<#list column as c>
				<if test="${c.fieldName} != null and ${c.fieldName} != ''">
	  				and ${c.columnName} = ${"#"}{${c.fieldName}}				
	  			</if>
	    	</#list>
    	</trim>
	</select>
</mapper>